//index.js
//获取应用实例
var app = getApp();
var util = require('../../utils/util');

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    barimages: ['../../images/bnav1h.png', '../../images/bnav2n.png', '../../images/bnav3n.png'],
    movies: [{ img: '../../pic/banner.jpg', redirectType: 0 }]
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },

  // 获取运动处方
  toPrescription() {
    util.sendRequest("WxGetUserInfo",{}, function (res) {
      
      
    const userInfo = wx.getStorageSync("userInfo");
    userInfo.isJlOk = res.result.isJlOk;
    userInfo.questionPos = res.result.questionPos;
    wx.setStorageSync("userInfo", userInfo);
        // util.sendRequest("WXUpdateQuestionState", { isOk: 0 });
    if (userInfo.isOverQuestion) {
      if(+userInfo.isJlOk){
      wx.navigateTo({
        url: '/pages/index/analysis',
        })
      }else{
        util.wxModalAlert({ content:"教练马上努力给您做计划，2-3天之后给您计划哟，别着急"});
      }
    } else {
     
      // 上次该用户答题位置
      const lastqNum = +userInfo.questionPos;
      // 如果是vip 直接进入答题
      if (1){
        // 第三个参数是设置当前批次题目是免费还是收费
        // 获取收费版题目
        util.getQuestion(lastqNum, res => {
          const data = res.result;
          wx.setStorageSync('questionItem', data);
          wx.redirectTo({
            url: '/pages/choose/question',
          })
        },1);
      }else{
        // 如果不是则进入缴费页面
        wx.redirectTo({
          url: '/pages/choose/version',
        })

      }
     
    }
    })
  },
  onLoad: function () {

    console.log(wx.getStorageSync("openid"));
    var that = this
    util.sendRequest('WXGetFocusList', { location: 1 }, function (resp) {

      that.setData({ movies: resp.result });
    }, '加载中...', function () {

    });
  },
  toLx: function () {
    wx.redirectTo({
      url: '/pages/personal/perplan2',
    })
  },
  toMine: function () {
    wx.redirectTo({
      url: '/pages/personal/percenter',
    })
  },
  focusClick: function (event) {
    var obj = event.target.dataset.obj;
  },
  onShareAppMessage: function () {
    return util.getShareMsg();
  }
})
